package com.qst.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qst.common.annotation.Log;
import com.qst.common.core.controller.BaseController;
import com.qst.common.core.domain.AjaxResult;
import com.qst.common.enums.BusinessType;
import com.qst.system.domain.Score;
import com.qst.system.domain.vo.ScoreVo;
import com.qst.system.service.IScoreService;
import com.qst.common.core.page.TableDataInfo;
import com.qst.common.utils.poi.ExcelUtil;

/**
 * 用户积分Controller
 * 
 * @author linzhe
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/system/score")
public class ScoreController extends BaseController
{
    @Autowired
    private IScoreService scoreService;

    /**
     * 查询用户积分列表
     */
    @PreAuthorize("@ss.hasPermi('system:score:list')")
    @GetMapping("/list")
    public TableDataInfo list(Score score)
    {
        startPage();
        List<ScoreVo> list = scoreService.selectScoreVoList(score);
        return getDataTable(list);
    }

    /**
     * 导出用户积分列表
     */
    @PreAuthorize("@ss.hasPermi('system:score:export')")
    @Log(title = "用户积分", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Score score)
    {
        List<ScoreVo> list = scoreService.selectScoreVoList(score);
        ExcelUtil<ScoreVo> util = new ExcelUtil<ScoreVo>(ScoreVo.class);
        return util.exportExcel(list, "用户积分数据");
    }

    /**
     * 获取用户积分详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:score:query')")
    @GetMapping(value = "/{scoreId}")
    public AjaxResult getInfo(@PathVariable("scoreId") Long scoreId)
    {
        return AjaxResult.success(scoreService.selectScoreById(scoreId));
    }

    /**
     * 新增用户积分
     */
    @PreAuthorize("@ss.hasPermi('system:score:add')")
    @Log(title = "用户积分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Score score)
    {
        return toAjax(scoreService.insertScore(score));
    }

    /**
     * 修改用户积分
     */
    @PreAuthorize("@ss.hasPermi('system:score:edit')")
    @Log(title = "用户积分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Score score)
    {
        return toAjax(scoreService.updateScore(score));
    }

    /**
     * 删除用户积分
     */
    @PreAuthorize("@ss.hasPermi('system:score:remove')")
    @Log(title = "用户积分", businessType = BusinessType.DELETE)
    @DeleteMapping("/{scoreIds}")
    public AjaxResult remove(@PathVariable Long[] scoreIds)
    {
        return toAjax(scoreService.deleteScoreByIds(scoreIds));
    }
    
    /**
     * 查询公司名称列表
     */
    @PreAuthorize("@ss.hasPermi('system:score:list')")
    @GetMapping("/comName")
    public AjaxResult getCompanyNameList()
    {
        // 获取所有公司名称
        List<String> companyNames = scoreService.selectCompanyNameList();
        return AjaxResult.success(companyNames);
    }
}